﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using RibbonEditor.LocLabels;

namespace RibbonEditor.Forms.LocLabels
{
    public partial class CreateLocLabelDialog : Form
    {
        XmlNode currentNode;

        public CreateLocLabelDialog(XmlNode node)
        {
            InitializeComponent();

            this.currentNode = node;
            this.FillControls();
            this.SetToolTips();
        }

        private void FillControls()
        {
            if (currentNode.Name != "LocLabels")
            {
                LocLabel localizedLabel = new LocLabel(currentNode);
                this.locLabelControl1.LocalizedLabel = localizedLabel;
                this.locLabelControl1.FillControls();
            }
        }

        private void SetToolTips()
        {
            //this.toolTip.SetToolTip(this.lblDisplayName, "Set the display name of the web resource");
            //this.toolTip.SetToolTip(this.lblName, "Set the schema name of the web resource");
            //this.toolTip.SetToolTip(this.lblFileName, "Set the path to the web resource in the customization archive");
            //this.toolTip.SetToolTip(this.lblType, "Set the type of the web resource");
        }


        private void btnValidate_Click(object sender, EventArgs e)
        {
            //if (currentNode.Name != "LocLabels")
            //{
                this.locLabelControl1.Save();

                XmlNode locLabelNode = XmlHelper.AddNode(this.currentNode, "LocLabel");
                XmlHelper.AddAttribute(locLabelNode, "Id", this.locLabelControl1.LocalizedLabel.Id);
                XmlNode titlesNode = XmlHelper.AddNode(locLabelNode, "Titles");

                foreach (Title title in this.locLabelControl1.LocalizedLabel.Titles.TitleList)
                {
                    XmlNode titleNode = XmlHelper.AddNode(titlesNode, "Title");
                    XmlHelper.AddAttribute(titleNode, "languagecode", title.LanguageCode);
                    XmlHelper.AddAttribute(titleNode, "description", title.Description);
                }
            //}

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
